package com.mobile.manager.controller;

import com.mobile.manager.pojo.Device;
import com.mobile.manager.service.IDeviceService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;

/**
 * Created by zhangdi on 16/5/30.
 */
@Controller
@RequestMapping("/device")
public class DeviceUIController {
    @Resource
    private IDeviceService deviceService;
    //展示新增设备页面
    @RequestMapping("/addDeviceUI")
    public String addDeviceUI(HttpServletRequest request,Model model){
        String id = request.getParameter("id");
        model.addAttribute("id",id);
        return  "addDeviceUI";
    }

    //展示日志监控页面
    @RequestMapping("/logMonitoring")
    public String showLogMonitor(HttpServletRequest request,Model model){

        return  "logMonitoring";
    }

    //展示设备更新页面
    @RequestMapping("editDeviceUI")
    public ModelAndView editDevice(@RequestParam(value="deviceId") String ID){
        int id = Integer.parseInt(ID);
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");//小写的mm表示的是分钟

        ModelAndView mv = new ModelAndView("editDeviceUI");
        Device device = this.deviceService.getDeviceById(id);
        String date = sdf.format(device.getBuy_time());
        device.setDate(date);
        mv.addObject("device",device);
        return mv;
    }

    //展示借用页面
    @RequestMapping("borrowDeviceUI")
    public ModelAndView borrowUI(@RequestParam(value="deviceId") String ID){
        int id = Integer.parseInt(ID);
        ModelAndView mv = new ModelAndView("borrowUI");
        Device device = this.deviceService.getDeviceById(id);
        mv.addObject("device",device);
        return mv;
    }
}
